//
//  MYBaseSettingViewController.m
//  奇闻
//
//  Created by 似水灵修 on 14-12-1.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYBaseSettingViewController.h"
#import "MYSettingCell.h"

@implementation MYBaseSettingViewController
- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}
- (NSMutableArray *)gorups
{
    if (nil == _gorups) {
        _gorups = [NSMutableArray array];
    }
    return _gorups;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.gorups.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    MYGroupItem *group = self.gorups[section];
    return group.items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MYSettingCell *cell = [MYSettingCell cellWithTableView:tableView];
    MYGroupItem *group = self.gorups[indexPath.section];
    cell.item = group.items[indexPath.row];
    return cell;
}
//返回头部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    MYGroupItem *group = self.gorups[section];
    return group.headTitel;
}
//返回尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    MYGroupItem *group = self.gorups[section];
    return group.footTitel;
}

//点击某一行cell的响应事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#warning 取消点击选中后的 选中效果
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    MYGroupItem *group = self.gorups[indexPath.section];
    MYSettingItem *settingItem = group.items[indexPath.row];
    if (settingItem.operateBlock) {
        settingItem.operateBlock(settingItem);
        return;
    }
    if (settingItem.destVCClass) {
        UIViewController *VC = [[settingItem.destVCClass alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
